using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MMM.Core.Domain;
using ServiceStack.ServiceHost;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using ServiceStack.ServiceInterface.Auth;
using ServiceStack.ServiceInterface;
using MMM.Services.Type;


namespace MMM.Services.Operations
{
    [Route("/api/user", "GET")]
    public class UserPageGet : PageGet<UserPageGet>
    {
        public int? isLock { get; set; }
    }
    [Serializable]
    [Route("api/usercheck", "GET,POST")]
    public class UserCheck : PageGet<UserCheck>
    {
        public string userName { get; set; }
        public string userPwd { get; set; }
    }



    public class MyUserSession : AuthUserSession
    {
        public List<Shop> ShopList { get; set; }
        public string UserPwd { get; set; }
        public Guid? UserID { get; set; }
    }

    public class MyCredentialsAuthProvider : CredentialsAuthProvider
    {
        public override bool TryAuthenticate(IServiceBase authService, string userName, string password)
        {
            if (!CheckInDB(userName, password)) return false;

            var session = (MyUserSession)authService.GetSession(false);
            session.UserAuthId = userName;
            session.IsAuthenticated = true;

            // add roles 
            //session.Roles = new List<string>();
            //if (session.UserAuthId == "admin") session.Roles.Add(RoleNames.Admin);
            //session.Roles.Add("User");

            return true;
        }

        private bool CheckInDB(string userName, string password)
        {
            if (userName != "admin" && userName != "user") return false;
            return password == "123";
        }
    }
}
